from django.core.management.base import BaseCommand

from ceph.ceph_manager import global_configs


class Command(BaseCommand):
    '''
    检测/添加全局配置参数
    '''
    help = """ 
            检测/添加全局配置参数
            python manage.py check_global_config
            or 
            [manage.py check_global_config --radmin];
           """

    def add_arguments(self, parser):
        parser.add_argument(
            '--radmin', default=None, dest='radmin', nargs='?', const=True,
            help='中坤管理员格式校验，将","转为换行',
        )

    def handle(self, *args, **options):
        print(options)

        radmin = options['radmin']

        if radmin:
            try:
                global_configs.check_site_parameter_resource_admin()
            except Exception as e:
                self.stdout.write(self.style.ERROR(
                    f"check error:{str(e)}"))

            self.stdout.write(
                self.style.SUCCESS(
                    'Successfully check resourceAdmin.'
                )
            )

            return

        try:
            global_configs.get_configs()
        except Exception as e:
            self.stdout.write(self.style.ERROR(
                f"error check global config:{str(e)}"))

        self.stdout.write(
            self.style.SUCCESS(
                'Successfully check global config.'
            )
        )
